/* CustomerController.java
 *
 * Copyright (C) 2013 Universidad de Sevilla
 * 
 * The use of this project is hereby constrained to the conditions of the 
 * TDG Licence, a copy of which you may download from 
 * http://www.tdg-seville.info/License.html
 * 
 */

package controllers;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import services.PaintingService;
import domain.Painting;

@Controller
@RequestMapping("/painting")
public class PaintingController extends AbstractController {

	//Services -----------------------------------------------------------------
	
	@Autowired
	PaintingService paintingService;
	
	// Constructors -----------------------------------------------------------

	public PaintingController() {
		super();
	}
	
	//List --------------------------------------------------------------------
	
	@RequestMapping("/listInGallery")
	public ModelAndView listInGallery(@RequestParam int galleryId) {
		ModelAndView result;
		Collection<Painting> paintings;
		paintings = paintingService.findPaintingsByGalleryId(galleryId);
		
		
		result = new ModelAndView("painting/list");
		result.addObject("paintings", paintings);
		result.addObject("URI", "/painting/listInGallery.do");
		return result;
	}
	
	@RequestMapping("/listOwned")
	public ModelAndView listOwned(@RequestParam int ownerId) {
		ModelAndView result;
		Collection<Painting> paintings;
		paintings = paintingService.findPaintingsByOwnerId(ownerId);
		
		
		result = new ModelAndView("painting/list");
		result.addObject("paintings", paintings);
		result.addObject("URI", "/painting/listOwned.do");
		return result;
	}

	
}